// memberVip/pages/memberRules/memberRules.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        pay: [],
        lie: [],
        huiyuan1: false,
        huiyuan2: false,
        huiyuan3: false,
        huiyuan4: false,
        huiyuan5: false,
        huiyuan6: false,
        rulest: true
    },
    //获取去右侧胶囊的信息
    getHeader() {
        let menuRect = wx.getMenuButtonBoundingClientRect();
        this.setData({
            topBarHeight: menuRect.height,
            topBarTop: menuRect.top
        });
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getHeader();
        let that = this;
        that.taocan();
        that.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        this.taocan();
        wx.stopPullDownRefresh();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    // 套餐渲染
    taocan: function() {
        var that = this;
        common.request({
            endpoint: "vipcard/vip-info",
            method: "POST",
            data: {},
            success: res => {
                let rule = "";
                if (res.extra.vip_set.rule == "" || res.extra.vip_set.rule == null || res.extra.vip_set.rule == undefined) {
                    rule = "暂无规则";
                } else {
                    rule = res.extra.vip_set.rule;
                }
                let name = "";
                if (res.extra.vip_set.name == "" || res.extra.vip_set.name == null || res.extra.vip_set.name == undefined) {
                    name = "--";
                } else {
                    name = res.extra.vip_set.name;
                }
                if (res.extra.vip_profit.profit_type.length > 0) {
                    var words = res.extra.vip_profit.profit_type.split(",");
                    for (var i = 0; i < words.length; i++) {
                        var numb = words[i];
                        if (numb == 1) {
                            that.setData({
                                huiyuan1: true
                            });
                        }
                        if (numb == 2) {
                            that.setData({
                                huiyuan2: true
                            });
                        }
                        if (numb == 3) {
                            that.setData({
                                huiyuan3: true
                            });
                        }
                        if (numb == 4) {
                            that.setData({
                                huiyuan4: true
                            });
                        }
                        if (numb == 5) {
                            that.setData({
                                huiyuan5: true
                            });
                        }
                        if (numb == 6) {
                            that.setData({
                                huiyuan6: true
                            });
                        }
                    }
                }
                that.setData({
                    pay: res.extra.vip_profit,
                    rule: rule,
                    name: name,
                    background_type: res.extra.vip_set.background_type,
                    background: res.extra.vip_set.background
                });
            }
        });
    },
    rulestPage: function() {
        var that = this;
        that.setData({
            rulest: false
        });
    },
    rulestclosePage: function() {
        var that = this;
        that.setData({
            rulest: true
        });
    }
});